require('../../mypublic/css/common.less');
require('../../mypublic/css/index.less');

require('./index.css');

require("jquery");
var utils = require('@yunke/core/util').default;


require('../../public/js/myservice/side');
require("../../public/js/myservice/authorize");

var angular = require('angular');

angular.module('app', [])
    .controller('mainCtrl', ['$scope', '$http', function ($scope, $http) {
        $scope.data = {
            model: {}
        };

        $scope.action = '/api/index.php?r=cms/dir/edit&id=' + utils.getUrlPara('id');

        window.postCallback = function (res) {
            if (res.retCode == -1) {
                $('#js_error_msg').html(res.retMsg);
                $scope.$applyAsync();
                alert('保存失败');
            } else {
                alert('保存成功');
                location.href = '/cms/dir_list/index.html';
            }
        };

        $scope.beforeSubmit = function (e) {
            $('#js_error_msg').html('');
            $scope.key = new Date().getTime();
        };

        $scope.$watch('statusChecked', function () {
            $scope.data.model.status = $scope.statusChecked ? 1 : 0;
        });

        $scope.$watch('externalDisplayChecked', function () {
            $scope.data.model.external_display = $scope.externalDisplayChecked ? 1 : 0;
        });

        $http.get('/api/index.php?r=/cms/dir/edit', {
                params: {id: utils.getUrlPara('id')}
            })
            .success(function (res) {
                var data = res.data;
                $scope.data = data;
                $scope.statusChecked = data.model.status == 1;
                $scope.externalDisplayChecked = data.model.external_display == 1;
            })
    }]);

angular.bootstrap(document, ['app']);
